Paso 1

Show code
script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"
Show code
 $(document).ready(function() {
    $('body').prepend('<div class=\"zoomDiv\"><img src=\"\" class=\"zoomImg\"></div>');
    // onClick function for all plots (img's)
    $('img:not(.zoomImg)').click(function() {
      $('.zoomImg').attr('src', $(this).attr('src')).css({width: '100%'});
      $('.zoomDiv').css({opacity: '1', width: 'auto', border: '1px solid white', borderRadius: '5px', position: 'fixed', top: '50%', left: '50%', marginRight: '-50%', transform: 'translate(-50%, -50%)', boxShadow: '0px 0px 50px #888888', zIndex: '50', overflow: 'auto', maxHeight: '100%'});
    });
    // onClick function for zoomImg
    $('img.zoomImg').click(function() {
      $('.zoomDiv').css({opacity: '0', width: '0%'}); 
    });
  });
  
Show code
<script src="hideOutput.js"></script> 
Show code
$(document).ready(function() {    
    $chunks = $('.fold');    
    $chunks.each(function () {      // add button to source code chunks     
    if ( $(this).hasClass('s') ) {       
        $('pre.r', this).prepend("<div class=\"showopt\">Show Source</div><br style=\"line-height:22px;\"/>");
            $('pre.r', this).children('code').attr('class', 'folded');     
            }      // add button to output chunks     
        if ( $(this).hasClass('o') ) {       
            $('pre:not(.r)', this).has('code').prepend("<div class=\"showopt\">Show Output</div><br style=\"line-height:22px;\"/>");       
            $('pre:not(.r)', this).children('code:not(r)').addClass('folded');        // add button to plots       
            $(this).find('img').wrap('<pre class=\"plot\"></pre>');       
            $('pre.plot', this).prepend("<div class=\"showopt\">Show Plot</div><br style=\"line-height:22px;\"/>");       
            $('pre.plot', this).children('img').addClass('folded');      
            }   
});    // hide all chunks when document is loaded   
    $('.folded').css('display', 'none')    // function to toggle the visibility   
    $('.showopt').click(function() {     
            var label = $(this).html();     
            if (label.indexOf("Show") >= 0) {       
                $(this).html(label.replace("Show", "Hide"));     
            } else {
              $(this).html(label.replace("Hide", "Show"));     
            }     
    $(this).siblings('code, img').slideToggle('fast', 'swing');   
    }); 
}); 
Show code
rm(list=ls());gc()
          used (Mb) gc trigger (Mb) max used (Mb)
Ncells  661896 35.4    1361635 72.8   931559 49.8
Vcells 1180020  9.1    8388608 64.0  2237384 17.1
Show code
Sys.setlocale("LC_COLLATE", "Spanish_Chile.1252")
[1] "Spanish_Chile.1252"
Show code
Sys.setlocale("LC_COLLATE", "Spanish_Chile.1252")
[1] "Spanish_Chile.1252"
Show code
Sys.setlocale("LC_CTYPE", "Spanish_Chile.1252")
[1] "Spanish_Chile.1252"
Show code
Sys.setlocale("LC_MONETARY", "Spanish_Chile.1252")
[1] "Spanish_Chile.1252"
Show code
Sys.setlocale("LC_TIME", "Spanish_Chile.1252")
[1] "Spanish_Chile.1252"
Show code
knitr::opts_chunk$set(echo = TRUE)
options(knitr.kable.NA = '')
Show code
if(!require(pacman)){install.packages("pacman")}
if(!require(devtools)){install.packages("devtools", type = "win.binary", dependencies=T)}
#pacman::p_unlock(lib.loc = pacman::p_path())
pacman::p_load(devtools, car, tidyverse, janitor, imputeTS, sjPlot, zoo, compareGroups, forecast, lubridate, gganimate, data.table, CausalImpact, panelView, ggforce, tsModel, astsa, plm, gsynth, Synth, CausalMBSTS, parallel, doParallel, PanelMatch, kableExtra, Amelia, missRanger, pglm, tabulizer, install=F)
# Calculate the number of cores
no_cores <- detectCores() - 1
cl<-makeCluster(no_cores)
registerDoParallel(cl)

octubre 18, 2022

Cargamos las bases de datos.

Show code
REM <- "https://docs.google.com/spreadsheets/u/0/d/1KtdHJ2FLDg4BOUa0KzCw4vawO7lmbZzh/export?format=tsv&id=1KtdHJ2FLDg4BOUa0KzCw4vawO7lmbZzh&gid=1716931764"
destfile <- "_data/brechas_gine_rem.tsv"
curl::curl_download(REM, destfile)
brechas_gine_REM <- readr::read_delim(destfile, delim = "\t", 
                      escape_double = FALSE, trim_ws = TRUE)
entradas <- "https://docs.google.com/spreadsheets/u/0/d/1KtdHJ2FLDg4BOUa0KzCw4vawO7lmbZzh/export?format=tsv&id=1KtdHJ2FLDg4BOUa0KzCw4vawO7lmbZzh&gid=1847489841"
destfile <- "_data/brechas_gine_entradas.tsv"
curl::curl_download(entradas, destfile)
brechas_gine_entradas <- readr::read_delim(destfile, delim = "\t", 
                      escape_double = FALSE, trim_ws = TRUE)
le <- "https://docs.google.com/spreadsheets/u/0/d/1KtdHJ2FLDg4BOUa0KzCw4vawO7lmbZzh/export?format=tsv&id=1KtdHJ2FLDg4BOUa0KzCw4vawO7lmbZzh&gid=1987038231"
destfile <- "_data/brechas_gine_le.tsv"
curl::curl_download(le, destfile)
brechas_gine_le <- readr::read_delim(destfile, delim = "\t", 
                      escape_double = FALSE, trim_ws = TRUE)


REM2 <- "https://docs.google.com/spreadsheets/u/0/d/1J5AGAVBBTF0FblpBNitx7d3sv6Sx0GeL/export?format=tsv&id=1J5AGAVBBTF0FblpBNitx7d3sv6Sx0GeL&gid=1566988382"
destfile <- "_data/brechas_gine_rem2.tsv"
curl::curl_download(REM2, destfile)
brechas_gine_REM2 <- readr::read_delim(destfile, delim = "\t", 
                      escape_double = FALSE, trim_ws = TRUE)

le2 <- "https://docs.google.com/spreadsheets/u/0/d/1B16EqrWer0So6w-SYoTiATlYnxwSOYBw/export?format=tsv&id=1B16EqrWer0So6w-SYoTiATlYnxwSOYBw&gid=960794881"
destfile <- "_data/brechas_gine_le2.tsv"
curl::curl_download(le2, destfile)
brechas_gine_le2 <- readr::read_delim(destfile, delim = "\t", 
                      escape_double = FALSE, trim_ws = TRUE)

entradas2<- "https://docs.google.com/spreadsheets/u/0/d/1ckFkC8GHiKSTnvXvt6-nw2BnIGNrglQ8/export?format=tsv&id=1ckFkC8GHiKSTnvXvt6-nw2BnIGNrglQ8&gid=1432173314"
destfile <- "_data/brechas_gine_entradas2.tsv"
curl::curl_download(entradas2, destfile)
brechas_gine_entradas2 <- readr::read_delim(destfile, delim = "\t", 
                      escape_double = FALSE, trim_ws = TRUE)


Consolidación de base de datos

Considerando el diseño ecológico de este estudio, que utiliza y analiza información de bases de datos secundarias, no fue necesario obtener aprobación de comité de ética acreditado y por lo tanto, tampoco un proceso de consentimiento informado

Paso 1. Limpiar las variables

Primero normalizamos y restringimos los nombres de cada base de datos, luego restringimos el resto de las bases de datos de acuerdo a los años y meses disponibles en la base de datos REM (Enero 2018 a Junio 2022), agrupando la suma de prestaciones de origen en la institución de destino por tipo de prestación, año y mes. Finalmente, combinamos las bases de datos. Más información sobre las especialidades y el formato se encuentra en https://redsalud.ssmso.cl/wp-content/uploads/2021/12/Protocolo-interoperabilidad-RCR_v1.4.2.pdf.

Show code
tabel <- extract_tables('https://redsalud.ssmso.cl/wp-content/uploads/2021/12/Protocolo-interoperabilidad-RCR_v1.4.2.pdf', pages = c(21,22))
especialidades<-
rbind.data.frame(tabel[[1]][-c(1:3),1:3],tabel[[2]][-c(1:3),1:3])

colnames(especialidades)<-
c(stringr::str_trim(stringr::str_c(tabel[[1]][1:3,1],sep=" ", collapse=" ")),
  stringr::str_trim(stringr::str_c(tabel[[1]][1:3,2],sep=" ", collapse=" ")),
  stringr::str_trim(stringr::str_c(tabel[[1]][1:3,3],sep=" ", collapse=" ")))

especialidades%>%
  knitr::kable("markdown", caption="Especialidades")
Table 1: Especialidades
Código SIGTE Código Norma 820 Especialidad Norma 820
07-001 01 ANATOMÍA PATOLÓGICA
07-002 02 ANESTESIOLOGÍA
07-003 03 CARDIOLOGÍA
07-004 04 CIRUGÍA GENERAL
07-005 05 CIRUGÍA DE CABEZA, CUELLO Y
MAXILOFACIAL
07-006 06 CIRUGÍA CARDIOVASCULAR
07-007 07 CIRUGÍA DE TÓRAX
07-008 08 CIRUGÍA PLÁSTICA Y REPARADORA
07-009 09 CIRUGÍA PEDIÁTRICA
07-010 10 CIRUGÍA VASCULAR PERIFÉRICA
07-011 11 COLOPROCTOLOGÍA
07-012 12 DERMATOLOGÍA
07-013 13 DIABETOLOGÍA
07-014 14 ENDOCRINOLOGÍA ADULTO
07-015 15 ENDOCRINOLOGÍA PEDIÁTRICA
07-016 16 ENFERMEDADES RESPIRATORIAS DEL
ADULTO (BRONCOPULMONAR)
07-017 17 ENFERMEDADES RESPIRATORIAS
PEDIÁTRICAS (BRONCOPULMONAR
PEDIATRICO)
07-018 18 GASTROENTEROLOGÍA ADULTO
07-019 19 GASTROENTEROLOGÍA PEDIÁTRICA
07-020 20 GENÉTICA CLÍNICA
07-021 21 GERIATRÍA
07-022 22 GINECOLOGÍA PEDIÁTRICA Y DE LA
ADOLESCENCIA
07-023 23 HEMATOLOGÍA
07-024 24 IMAGENOLOGÍA
07-025 25 INFECTOLOGÍA
07-026 26 INMUNOLOGÍA
07-027 27 LABORATORIO CLÍNICO
07-028 28 MEDICINA FAMILIAR
07-029 29 MEDICINA FÍSICA Y REHABILITACIÓN
(FISIATRIA ADULTO)
07-030 30 MEDICINA INTERNA
07-031 31 MEDICINA INTENSIVA ADULTO
07-032 32 MEDICINA INTENSIVA PEDIÁTRICA
07-033 33 MEDICINA LEGAL
07-034 34 MEDICINA MATERNO INFANTIL
07-035 35 MEDICINA NUCLEAR
07-036 36 MEDICINA DE URGENCIA
07-037 37 NEFROLOGÍA ADULTO
07-038 38 NEFROLOGÍA PEDIÁTRICO
07-039 39 NEONATOLOGÍA
07-040 40 NEUROCIRUGÍA
07-041 41 NEUROLOGÍA ADULTO
07-042 42 NEUROLOGÍA PEDIÁTRICA
07-043 43 OBSTETRICIA Y GINECOLOGÍA
07-044 44 OFTALMOLOGÍA
07-045 45 ONCOLOGÍA MÉDICA
07-046 46 OTORRINOLARINGOLOGÍA
07-047 47 PEDIATRÍA
07-048 48 PSIQUIATRÍA ADULTO
07-049 49 PSIQUIATRÍA PEDIÁTRICA Y DE LA
ADOLESCENCIA
07-050 50 RADIOTERAPIA ONCOLÓGICA
07-051 51 REUMATOLOGÍA
07-052 52 SALUD PÚBLICA
07-053 53 TRAUMATOLOGÍA Y ORTOPEDIA
07-054 54 UROLOGÍA
07-055 55 CARDIOLOGÍA PEDIÁTRICA
07-056 56 CIRUGÍA DIGESTIVA
07-057 57 CIRUGÍA PLASTICA Y REPARADORA
PEDIÁTRICA
07-058 58 GINECOLOGÍA
07-059 59 HEMATO-ONCOLOGÍA PEDIÁTRICA
07-060 60 INFECTOLOGÍA PEDIATRICA
07-061 61 MEDICINA FAMILIAR DEL NIÑO
07-062 62 MEDICINA FISICA Y REHABILITACIÓN
PEDIÁTRICA (FISIATRIA PEDIATRICA)
07-063 63 NUTRIÓLOGO
07-064 64 NUTRIÓLOGO PEDIÁTRICO
07-065 65 REUMATOLOGÍA PEDIÁTRICA
07-066 66 OBSTETRICIA
07-067 67 TRAUMATOLOGÍA Y ORTOPEDIA
PEDIÁTRICA
07-068 68 UROLOGÍA PEDIÁTRICA
09-001 01 CIRUGÍA Y TRAUMATOLOGÍA BUCO
MAXILOFACIAL
09-002 02 CIRUGÍA BUCAL
09-003 03 ENDODONCIA
09-004 04 IMAGENOLOGÍA ORAL Y
MAXILOFACIAL
09-005 05 IMPLANTOLOGIA BUCO
MAXILOFACIAL
09-006 06 ODONTOLOGÍA LEGAL
09-007 07 ODONTOPEDIATRÍA
09-008 08 ORTODONCIA Y ORTOPEDIA DENTO
MÁXILO FACIAL
09-009 09 PATOLOGÍA ORAL
09-010 10 PERIODONCIA
09-030 30 REHABILITACIÓN ORAL
09-011 11 REHABILITACIÓN ORAL
09-012 12 SALUD PÚBLICA
09-013 13 SOMATO-PRÓTESIS
09-014 14 TRASTORNOS
TEMPOROMANDIBULARES Y DOLOR
OROFACIAL

Decidimos seleccionar 15 especialidades transversales, es decir, que están en los cuatro hospitales y tienen mayor demanda:


1.0. REM

Show code
janitor::clean_names(brechas_gine_REM2) %>% 
  dplyr::left_join(especialidades[,c(1,3)], by=c("cod_sigte"="Código SIGTE")) %>% 
  data.table::as.data.table() %>% 
  janitor::clean_names() %>% 
  dplyr::filter(cod_sigte %in% c("07-067","07-053", "07-046", "07-044", "07-004", "07-012", "07-058", "07-003", "07-041", "07-030", "07-054", "07-018", "07-014", "07-048", "07-037", "07-049")) %>% 
  dplyr::arrange(cod_sigte, ano, mes) %>% 
  dplyr::mutate(fecha=as.Date(paste0(ano,"_",mes,"_01"),"%Y_%m_%d")) %>% 
  #para cada establecimiento, prestación y año, genero valores con los distintos meses del año si no están
  dplyr::group_by(cod_sigte,especialidad_norma_820, ano) %>% 
  tidyr::complete(mes = seq(1, 12)) %>%
  dplyr::ungroup() %>% 
  dplyr::filter(ano>2017, ano<2021) %>% 
  dplyr::group_by(cod_sigte,especialidad_norma_820) %>% 
  dplyr::summarise(n_registros=n(), min_consultas_nva=min(consultas_nueva, na.rm=T), prom_consultas_nva=mean(consultas_nueva, na.rm=T), p25_consultas_nva=quantile(consultas_nueva, .25, na.rm=T), mdn_consultas_nva=quantile(consultas_nueva, .5, na.rm=T), p75_consultas_nva=quantile(consultas_nueva, .25, na.rm=T), max_consultas_nva=max(consultas_nueva, na.rm=T), 
                   min_nsp_nva=min(nsp_nueva, na.rm=T), prom_nsp_nva=mean(nsp_nueva, na.rm=T), p25_nsp_nva=quantile(nsp_nueva, .25, na.rm=T), mdn_nsp_nva=quantile(nsp_nueva, .5, na.rm=T), p75_nsp_nva=quantile(nsp_nueva, .25, na.rm=T), max_nsp_nva=max(nsp_nueva, na.rm=T),
        min_pert=min(pertinentes, na.rm=T), prom_pert=mean(pertinentes, na.rm=T), p25_pert=quantile(pertinentes, .25, na.rm=T), mdn_pert=quantile(pertinentes, .5, na.rm=T), p75_pert=quantile(pertinentes, .25, na.rm=T), max_pert=max(pertinentes, na.rm=T),
                   sum_nas_fechas=sum(is.na(fecha)), min_fecha=min(fecha, na.rm=T), max_fecha=max(fecha, na.rm=T)) %>% 
  knitr::kable("markdown", caption="Características de datos por prestación REM, en fechas entre 2018 y 2020") 
Table 2: Características de datos por prestación REM, en fechas entre 2018 y 2020
cod_sigte especialidad_norma_820 n_registros min_consultas_nva prom_consultas_nva p25_consultas_nva mdn_consultas_nva p75_consultas_nva max_consultas_nva min_nsp_nva prom_nsp_nva p25_nsp_nva mdn_nsp_nva p75_nsp_nva max_nsp_nva min_pert prom_pert p25_pert mdn_pert p75_pert max_pert sum_nas_fechas min_fecha max_fecha
07-003 CARDIOLOGÍA 540 0 34.044444 0 0 0 508 0 3.085185 0 0 0 120 0 7.131481 0 0 0 176 0 2018-01-01 2020-12-01
07-004 CIRUGÍA GENERAL 540 0 47.640741 0 0 0 460 0 3.253704 0 0 0 105 0 22.618519 0 0 0 419 0 2018-01-01 2020-12-01
07-012 DERMATOLOGÍA 540 0 41.825926 0 0 0 675 0 9.629630 0 0 0 161 0 17.016667 0 0 0 339 0 2018-01-01 2020-12-01
07-014 ENDOCRINOLOGÍA ADULTO 540 0 15.374074 0 0 0 154 0 1.490741 0 0 0 34 0 6.479630 0 0 0 71 0 2018-01-01 2020-12-01
07-018 GASTROENTEROLOGÍA ADULTO 540 0 14.750000 0 0 0 220 0 1.498148 0 0 0 38 0 5.427778 0 0 0 111 0 2018-01-01 2020-12-01
07-030 MEDICINA INTERNA 540 0 45.475926 0 0 0 481 0 6.268518 0 0 0 137 0 11.866667 0 0 0 196 0 2018-01-01 2020-12-01
07-037 NEFROLOGÍA ADULTO 540 0 14.227778 0 0 0 185 0 1.607407 0 0 0 36 0 6.083333 0 0 0 85 0 2018-01-01 2020-12-01
07-041 NEUROLOGÍA ADULTO 540 0 33.385185 0 0 0 307 0 4.438889 0 0 0 89 0 12.870370 0 0 0 160 0 2018-01-01 2020-12-01
07-044 OFTALMOLOGÍA 540 0 94.477778 0 0 0 1429 0 9.525926 0 0 0 129 0 29.818518 0 0 0 406 0 2018-01-01 2020-12-01
07-046 OTORRINOLARINGOLOGÍA 540 0 62.646296 0 0 0 695 0 8.900000 0 0 0 125 0 21.357407 0 0 0 281 0 2018-01-01 2020-12-01
07-048 PSIQUIATRÍA ADULTO 540 0 11.442593 0 0 0 99 0 5.166667 0 0 0 93 0 4.646296 0 0 0 61 0 2018-01-01 2020-12-01
07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 540 0 4.918519 0 0 0 58 0 3.361111 0 0 0 75 0 1.877778 0 0 0 36 0 2018-01-01 2020-12-01
07-053 TRAUMATOLOGÍA Y ORTOPEDIA 540 0 88.025926 0 0 0 1002 0 8.601852 0 0 0 179 0 29.414815 0 0 0 364 0 2018-01-01 2020-12-01
07-054 UROLOGÍA 540 0 35.109259 0 0 0 377 0 3.561111 0 0 0 71 0 16.231482 0 0 0 209 0 2018-01-01 2020-12-01
07-058 GINECOLOGÍA 540 0 47.581482 0 0 0 524 0 6.368519 0 0 0 133 0 30.553704 0 0 0 307 0 2018-01-01 2020-12-01
07-067 TRAUMATOLOGÍA Y ORTOPEDIA 540 0 37.322222 0 0 0 903 0 11.151852 0 0 0 407 0 10.683333 0 0 0 151 0 2018-01-01 2020-12-01
Show code
  #knitr::kable("html", caption="Características de datos por prestación REM, en fechas entre 2018 y 2020") %>% 
  #kableExtra::kable_classic()

1.1. Entradas

Show code
#https://cran.r-project.org/web/packages/PanelMatch/vignettes/using_panelmatch.pdf
#https://cran.r-project.org/web/packages/PanelMatch/vignettes/matched_set_objects.html
#https://cran.r-project.org/web/packages/pampe/pampe.pdf}


#seleccionamos los años y meses disponibles de la base original
vector_ano_mes<-
janitor::clean_names(brechas_gine_REM2) %>% dplyr::mutate(ano_mes=paste0(ano,"_",sprintf("%.2d", mes))) %>% distinct(ano_mes)


janitor::clean_names(brechas_gine_entradas2)[,c("estab_dest", "presta_min", "ano", "mes", "n_entradas")] %>% 
    dplyr::left_join(especialidades[,c(1,3)], by=c("presta_min"="Código SIGTE")) %>% 
    data.table::as.data.table() %>% 
    janitor::clean_names() %>%  
    dplyr::filter(presta_min %in% c("07-067","07-053", "07-046", "07-044", "07-004", "07-012", "07-058", "07-003", "07-041", "07-030", "07-054", "07-018", "07-014", "07-048", "07-037", "07-049")) %>% 
    dplyr::arrange(estab_dest, especialidad_norma_820, presta_min, ano, mes) %>% 
    #para cada establecimiento, prestación y año, genero valores con los distintos meses del año si no están
    dplyr::mutate(mes2=mes) %>% 
    dplyr::group_by(estab_dest, especialidad_norma_820, presta_min, ano) %>% 
    tidyr::complete(mes2 = seq(1, 12)) %>% 
    dplyr::ungroup() %>%
    dplyr::filter(is.na(mes), ano>2017, ano<2021) %>%
    dplyr::group_by(estab_dest, especialidad_norma_820, presta_min) %>% 
    summarise(n=n()) %>% 
  dplyr::arrange(desc(n)) %>% 
  knitr::kable("markdown", caption="Número de meses sin datos por Establecimiento y prestación, en fechas entre 2018 y 2020")
Table 3: Número de meses sin datos por Establecimiento y prestación, en fechas entre 2018 y 2020
estab_dest especialidad_norma_820 presta_min n
114408 OFTALMOLOGÍA 07-044 21
114306 OTORRINOLARINGOLOGÍA 07-046 19
200282 PSIQUIATRÍA PEDIÁTRICA Y DE LA 07-049 17
200282 TRAUMATOLOGÍA Y ORTOPEDIA 07-067 14
114010 PSIQUIATRÍA PEDIÁTRICA Y DE LA 07-049 11
114305 OFTALMOLOGÍA 07-044 11
114311 OFTALMOLOGÍA 07-044 11
114314 PSIQUIATRÍA ADULTO 07-048 11
114316 OFTALMOLOGÍA 07-044 11
114331 OTORRINOLARINGOLOGÍA 07-046 11
114410 OFTALMOLOGÍA 07-044 11
114609 PSIQUIATRÍA PEDIÁTRICA Y DE LA 07-049 11
114306 GASTROENTEROLOGÍA ADULTO 07-018 9
114714 OFTALMOLOGÍA 07-044 9
114315 OFTALMOLOGÍA 07-044 8
114328 OTORRINOLARINGOLOGÍA 07-046 7
114306 OFTALMOLOGÍA 07-044 6
114105 TRAUMATOLOGÍA Y ORTOPEDIA 07-067 4
114101 PSIQUIATRÍA PEDIÁTRICA Y DE LA 07-049 3
200282 DERMATOLOGÍA 07-012 3
114101 ENDOCRINOLOGÍA ADULTO 07-014 2
200282 NEFROLOGÍA ADULTO 07-037 2
114105 PSIQUIATRÍA PEDIÁTRICA Y DE LA 07-049 1
114323 OFTALMOLOGÍA 07-044 1
200282 GINECOLOGÍA 07-058 1
200282 OFTALMOLOGÍA 07-044 1
Show code
janitor::clean_names(brechas_gine_entradas2)[,c("estab_dest", "presta_min", "ano", "mes", "n_entradas")] %>% 
  dplyr::left_join(especialidades[,c(1,3)], by=c("presta_min"="Código SIGTE")) %>% 
      data.table::as.data.table() %>% 
      janitor::clean_names() %>%  
      dplyr::filter(presta_min %in% c("07-067","07-053", "07-046", "07-044", "07-004", "07-012", "07-058", "07-003", "07-041", "07-030", "07-054", "07-018", "07-014", "07-048", "07-037", "07-049")) %>%   dplyr::arrange(estab_dest, presta_min, especialidad_norma_820, ano, mes) %>% 
  dplyr::mutate(fecha=as.Date(paste0(ano,"_",mes,"_01"),"%Y_%m_%d")) %>% 
  #para cada establecimiento, prestación y año, genero valores con los distintos meses del año si no están
  dplyr::group_by(estab_dest, presta_min,especialidad_norma_820, ano) %>% 
  tidyr::complete(mes = seq(1, 12)) %>%
  dplyr::ungroup() %>% 
  dplyr::filter(ano>2017, ano<2021) %>% 
  dplyr::group_by(estab_dest, presta_min,especialidad_norma_820) %>% 
  dplyr::summarise(n_registros=n(), min_entradas=min(n_entradas, na.rm=T), prom_entradas= mean(n_entradas, na.rm=T), p25_entradas=quantile(n_entradas, .25, na.rm=T), mdn_entradas=quantile(n_entradas, .5, na.rm=T), p75_entradas=quantile(n_entradas, .75, na.rm=T), max_entradas=max(n_entradas, na.rm=T), sum_nas_fechas=sum(is.na(fecha)), min_fecha=min(fecha, na.rm=T), max_fecha=max(fecha, na.rm=T)) %>% 
  knitr::kable("markdown", caption="Características de datos por Establecimiento y prestación, en fechas entre 2018 y 2020")
Table 4: Características de datos por Establecimiento y prestación, en fechas entre 2018 y 2020
estab_dest presta_min especialidad_norma_820 n_registros min_entradas prom_entradas p25_entradas mdn_entradas p75_entradas max_entradas sum_nas_fechas min_fecha max_fecha
114010 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 12 1 1.000000 1.00 1.0 1.00 1 11 2018-01-01 2018-01-01
114101 07-003 CARDIOLOGÍA 510 1 21.582353 1.00 3.0 9.00 460 0 2018-01-01 2020-12-01
114101 07-004 CIRUGÍA GENERAL 540 1 21.711111 2.00 5.0 12.00 411 0 2018-01-01 2020-12-01
114101 07-012 DERMATOLOGÍA 605 1 17.147107 2.00 4.0 12.00 297 0 2018-01-01 2020-12-01
114101 07-014 ENDOCRINOLOGÍA ADULTO 331 1 7.693009 1.00 2.0 4.00 129 2 2018-01-01 2020-12-01
114101 07-018 GASTROENTEROLOGÍA ADULTO 484 1 12.305785 1.00 3.0 6.00 226 0 2018-01-01 2020-12-01
114101 07-030 MEDICINA INTERNA 404 1 46.118812 1.00 3.0 6.00 775 0 2018-01-01 2020-12-01
114101 07-037 NEFROLOGÍA ADULTO 259 1 7.741313 1.00 2.0 3.00 142 0 2018-01-01 2020-12-01
114101 07-041 NEUROLOGÍA ADULTO 464 1 19.015086 1.00 3.0 9.00 502 0 2018-01-01 2020-12-01
114101 07-044 OFTALMOLOGÍA 915 1 24.185792 1.00 5.0 13.00 958 0 2018-01-01 2020-12-01
114101 07-046 OTORRINOLARINGOLOGÍA 546 1 25.615385 1.00 5.0 14.00 442 0 2018-01-01 2020-12-01
114101 07-048 PSIQUIATRÍA ADULTO 217 1 8.958525 1.00 2.0 4.00 140 0 2018-01-01 2020-12-01
114101 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 211 1 5.639423 1.00 1.0 2.25 125 3 2018-01-01 2020-12-01
114101 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 590 1 30.110170 2.00 5.0 13.00 1495 0 2018-01-01 2020-12-01
114101 07-054 UROLOGÍA 408 1 14.174020 1.00 3.0 7.25 252 0 2018-01-01 2020-12-01
114101 07-058 GINECOLOGÍA 676 1 10.849112 2.00 4.0 10.00 266 0 2018-01-01 2020-12-01
114101 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 425 1 18.983529 1.00 3.0 6.00 1351 0 2018-01-01 2020-12-01
114103 07-003 CARDIOLOGÍA 475 1 6.696842 1.00 2.0 4.00 93 0 2018-01-01 2020-12-01
114103 07-004 CIRUGÍA GENERAL 496 1 5.949597 2.00 3.0 6.00 81 0 2018-01-01 2020-12-01
114103 07-012 DERMATOLOGÍA 593 1 11.635750 3.00 7.0 12.00 254 0 2018-01-01 2020-12-01
114103 07-014 ENDOCRINOLOGÍA ADULTO 450 1 3.802222 1.00 2.0 4.00 42 0 2018-01-01 2020-12-01
114103 07-018 GASTROENTEROLOGÍA ADULTO 415 1 4.744578 1.00 2.0 3.00 58 0 2018-01-01 2020-12-01
114103 07-030 MEDICINA INTERNA 477 1 9.949685 1.00 2.0 4.00 139 0 2018-01-01 2020-12-01
114103 07-037 NEFROLOGÍA ADULTO 170 1 3.623529 1.00 1.0 2.00 37 0 2018-01-01 2020-12-01
114103 07-041 NEUROLOGÍA ADULTO 482 1 6.834025 1.00 3.0 5.00 141 0 2018-01-01 2020-12-01
114103 07-044 OFTALMOLOGÍA 495 1 8.070707 2.00 3.0 7.00 249 0 2018-01-01 2020-12-01
114103 07-046 OTORRINOLARINGOLOGÍA 557 1 9.576302 2.00 5.0 9.00 211 0 2018-01-01 2020-12-01
114103 07-048 PSIQUIATRÍA ADULTO 341 1 4.695015 1.00 1.0 2.00 57 0 2018-01-01 2020-12-01
114103 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 195 1 3.271795 1.00 1.0 2.00 39 0 2018-01-01 2020-12-01
114103 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 555 1 8.291892 3.00 5.0 9.00 117 0 2018-01-01 2020-12-01
114103 07-054 UROLOGÍA 517 1 7.085106 2.00 3.0 5.00 122 0 2018-01-01 2020-12-01
114103 07-058 GINECOLOGÍA 594 1 13.247475 4.00 8.0 18.00 216 0 2018-01-01 2020-12-01
114103 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 310 1 2.935484 1.00 2.0 3.00 38 0 2018-01-01 2020-12-01
114105 07-003 CARDIOLOGÍA 367 1 10.405995 3.00 5.0 8.00 89 0 2018-01-01 2020-12-01
114105 07-004 CIRUGÍA GENERAL 374 1 15.377005 8.00 13.0 20.00 62 0 2018-01-01 2020-12-01
114105 07-012 DERMATOLOGÍA 381 1 14.083989 5.00 10.0 17.00 75 0 2018-01-01 2020-12-01
114105 07-014 ENDOCRINOLOGÍA ADULTO 349 1 6.988539 3.00 5.0 8.00 42 0 2018-01-01 2020-12-01
114105 07-018 GASTROENTEROLOGÍA ADULTO 327 1 5.727829 1.00 2.0 4.00 50 0 2018-01-01 2020-12-01
114105 07-030 MEDICINA INTERNA 273 1 7.282051 1.00 2.0 4.00 69 0 2018-01-01 2020-12-01
114105 07-037 NEFROLOGÍA ADULTO 246 1 4.422764 1.00 2.0 4.00 35 0 2018-01-01 2020-12-01
114105 07-041 NEUROLOGÍA ADULTO 392 1 12.301020 4.00 7.0 12.00 163 0 2018-01-01 2020-12-01
114105 07-044 OFTALMOLOGÍA 359 1 20.183844 6.50 12.0 22.00 185 0 2018-01-01 2020-12-01
114105 07-046 OTORRINOLARINGOLOGÍA 381 1 18.527559 8.00 16.0 24.00 79 0 2018-01-01 2020-12-01
114105 07-048 PSIQUIATRÍA ADULTO 272 1 8.165441 1.00 2.0 3.00 110 0 2018-01-01 2020-12-01
114105 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 180 1 5.363129 1.00 2.0 3.00 85 1 2018-01-01 2020-12-01
114105 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 377 1 17.527852 9.00 15.0 23.00 71 0 2018-01-01 2020-12-01
114105 07-054 UROLOGÍA 378 1 10.693122 5.00 8.0 13.00 57 0 2018-01-01 2020-12-01
114105 07-058 GINECOLOGÍA 361 1 15.041551 7.00 12.0 18.00 77 0 2018-01-01 2020-12-01
114105 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 246 1 6.161157 1.00 3.0 6.00 79 4 2018-01-01 2020-12-01
114305 07-044 OFTALMOLOGÍA 12 1 1.000000 1.00 1.0 1.00 1 11 2019-06-01 2019-06-01
114306 07-018 GASTROENTEROLOGÍA ADULTO 12 1 1.000000 1.00 1.0 1.00 1 9 2019-05-01 2019-09-01
114306 07-044 OFTALMOLOGÍA 39 1 35.757576 2.00 4.0 79.00 150 6 2018-03-01 2019-08-01
114306 07-046 OTORRINOLARINGOLOGÍA 43 1 5.125000 1.00 3.0 10.25 14 19 2018-04-01 2020-08-01
114311 07-044 OFTALMOLOGÍA 12 1 1.000000 1.00 1.0 1.00 1 11 2019-09-01 2019-09-01
114314 07-048 PSIQUIATRÍA ADULTO 12 1 1.000000 1.00 1.0 1.00 1 11 2018-09-01 2018-09-01
114315 07-044 OFTALMOLOGÍA 36 1 11.642857 1.75 6.0 20.50 40 8 2018-02-01 2020-12-01
114316 07-044 OFTALMOLOGÍA 12 1 1.000000 1.00 1.0 1.00 1 11 2019-06-01 2019-06-01
114318 07-046 OTORRINOLARINGOLOGÍA 72 1 1.597222 1.00 1.0 2.00 5 0 2018-01-01 2019-12-01
114323 07-044 OFTALMOLOGÍA 59 1 6.000000 2.00 4.5 9.00 20 1 2018-01-01 2019-11-01
114328 07-046 OTORRINOLARINGOLOGÍA 14 1 1.285714 1.00 1.0 1.00 3 7 2018-01-01 2018-08-01
114331 07-046 OTORRINOLARINGOLOGÍA 105 1 1.457447 1.00 1.0 2.00 5 11 2018-01-01 2020-01-01
114408 07-044 OFTALMOLOGÍA 24 1 5.333333 1.00 1.0 7.50 14 21 2019-04-01 2020-03-01
114410 07-044 OFTALMOLOGÍA 12 1 1.000000 1.00 1.0 1.00 1 11 2018-03-01 2018-03-01
114609 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 12 1 1.000000 1.00 1.0 1.00 1 11 2018-02-01 2018-02-01
114714 07-044 OFTALMOLOGÍA 21 20 44.000000 28.75 44.5 51.25 82 9 2019-01-01 2019-03-01
200282 07-003 CARDIOLOGÍA 233 1 10.643777 3.00 7.0 13.00 81 0 2018-01-01 2020-12-01
200282 07-004 CIRUGÍA GENERAL 225 1 17.808889 6.00 13.0 25.00 101 0 2018-01-01 2020-12-01
200282 07-012 DERMATOLOGÍA 146 1 14.727273 2.00 12.0 19.50 125 3 2018-01-01 2020-12-01
200282 07-014 ENDOCRINOLOGÍA ADULTO 192 1 6.145833 1.00 3.0 6.00 51 0 2018-01-01 2020-12-01
200282 07-018 GASTROENTEROLOGÍA ADULTO 227 1 11.290749 2.00 4.0 13.00 78 0 2018-01-01 2020-12-01
200282 07-030 MEDICINA INTERNA 216 1 13.203704 3.00 7.0 15.00 90 0 2018-01-01 2020-12-01
200282 07-037 NEFROLOGÍA ADULTO 125 1 4.138211 1.00 2.0 5.50 18 2 2018-01-01 2020-12-01
200282 07-041 NEUROLOGÍA ADULTO 210 1 9.390476 3.00 5.0 12.00 50 0 2018-01-01 2020-12-01
200282 07-044 OFTALMOLOGÍA 211 1 17.371429 4.00 10.0 23.00 110 1 2018-01-01 2020-12-01
200282 07-046 OTORRINOLARINGOLOGÍA 222 1 17.490991 5.00 13.0 21.75 92 0 2018-01-01 2020-12-01
200282 07-048 PSIQUIATRÍA ADULTO 201 1 5.731343 2.00 4.0 8.00 36 0 2018-01-01 2020-12-01
200282 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 90 1 2.369863 1.00 2.0 3.00 12 17 2018-01-01 2020-05-01
200282 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 227 1 20.493392 5.50 13.0 28.00 92 0 2018-01-01 2020-12-01
200282 07-054 UROLOGÍA 230 1 7.460870 2.00 5.0 10.00 35 0 2018-01-01 2020-12-01
200282 07-058 GINECOLOGÍA 233 1 11.926724 2.00 8.0 14.00 274 1 2018-01-01 2020-12-01
200282 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 43 1 4.517241 1.00 2.0 5.00 16 14 2018-01-01 2019-03-01
Show code
     # knitr::kable("html", caption="Características de datos por Establecimiento y prestación, en fechas entre 2018 y 2020") %>% 
     # kableExtra::kable_classic()
Show code
#_#_#_#_#_#_#_#_
#_#_#_#_#_#_#_#_ENTRADAS
#_#_#_#_#_#_#_#_
brechas_gine_entradas_mod<-
janitor::clean_names(brechas_gine_entradas2)[,c("estab_dest", "presta_min", "ano", "mes", "n_entradas")] %>% 
      dplyr::filter(presta_min %in% c("07-067","07-053", "07-046", "07-044", "07-004", "07-012", "07-058", "07-003", "07-041", "07-030", "07-054", "07-018", "07-014", "07-048", "07-037", "07-049")) %>%   
  dplyr::arrange(estab_dest, presta_min, ano, mes) %>%
  dplyr::filter(ano>2017, ano<2021) %>% 
  #para cada establecimiento, prestación y año, genero valores con los distintos meses del año si no están
  dplyr::group_by(estab_dest, presta_min, ano) %>% 
  tidyr::complete(mes = seq(1, 12)) %>% 
  dplyr::ungroup() %>% 
  #generamos una variable llamada ano-mes, para homologar nuestros datos a la base original
  dplyr::mutate(ano_mes=paste0(ano,"_",sprintf("%.2d", mes))) %>% 
  dplyr::group_by(estab_dest, presta_min, ano_mes, ano, mes) %>% 
  dplyr::summarise(n_entradas_tot=sum(n_entradas, na.rm=T)) %>%
  #dplyr::filter(ano_mes=="2020_05") 
#_#_#_#_#_#_#_#_
  dplyr::ungroup() %>% 
  #filtro para que coincida con la base de datos de REM
  dplyr::filter(ano_mes %in% unlist(vector_ano_mes))#%>% 


1.2. LE

Show code
janitor::clean_names(brechas_gine_le2)[,c("estab_dest", "presta_min", "corte_sigte", "n_registros")] %>% 
  dplyr::filter(presta_min %in% c("07-067","07-053", "07-046", "07-044", "07-004", "07-012", "07-058", "07-003", "07-041", "07-030", "07-054", "07-018", "07-014", "07-048", "07-037", "07-049")) %>% 
  dplyr::left_join(especialidades[,c(1,3)], by=c("presta_min"="Código SIGTE")) %>% 
    data.table::as.data.table() %>% 
    janitor::clean_names() %>%  
  dplyr::mutate(mes_14= month(corte_sigte), mes=mes_14, ano_13=year(corte_sigte)) %>% 
  dplyr::arrange(estab_dest, presta_min, especialidad_norma_820, ano_13, mes_14) %>% 
  #para cada establecimiento, prestación y año, genero valores con los distintos meses del año si no están
  dplyr::group_by(estab_dest, presta_min, especialidad_norma_820, ano_13) %>% 
  tidyr::complete(mes_14 = seq(1, 12)) %>%
  dplyr::ungroup() %>% 
  dplyr::filter(ano_13>2017, ano_13<2021) %>% 
  dplyr::group_by(estab_dest, presta_min, especialidad_norma_820) %>% 
  dplyr::summarise(n_registros= n(), min_n_registros= min(n_registros, na.rm=T), max_n_registros= max(n_registros, na.rm=T), sum_nas_fechas= sum(is.na(corte_sigte)), min_fecha= min(corte_sigte, na.rm=T), max_fecha= max(corte_sigte, na.rm=T)) %>% 
  knitr::kable("markdown", caption="Características de datos por Establecimiento y prestación, en fechas entre 2018 y 2020")
Table 5: Características de datos por Establecimiento y prestación, en fechas entre 2018 y 2020
estab_dest presta_min especialidad_norma_820 n_registros min_n_registros max_n_registros sum_nas_fechas min_fecha max_fecha
114101 07-003 CARDIOLOGÍA 1053 1053 1053 14 2018-08-16 2020-12-15
114101 07-004 CIRUGÍA GENERAL 1458 1458 1458 14 2018-08-16 2020-12-15
114101 07-012 DERMATOLOGÍA 1085 1085 1085 14 2018-08-16 2020-12-15
114101 07-014 ENDOCRINOLOGÍA ADULTO 745 745 745 14 2018-08-16 2020-12-15
114101 07-018 GASTROENTEROLOGÍA ADULTO 1038 1038 1038 14 2018-08-16 2020-12-15
114101 07-030 MEDICINA INTERNA 673 673 673 14 2018-08-16 2020-12-15
114101 07-037 NEFROLOGÍA ADULTO 398 398 398 14 2018-08-16 2020-12-15
114101 07-041 NEUROLOGÍA ADULTO 665 665 665 14 2018-08-16 2020-12-15
114101 07-044 OFTALMOLOGÍA 2007 2007 2007 14 2018-08-16 2020-12-15
114101 07-046 OTORRINOLARINGOLOGÍA 1618 1618 1618 14 2018-08-16 2020-12-15
114101 07-048 PSIQUIATRÍA ADULTO 308 308 308 14 2018-08-16 2020-12-15
114101 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 276 276 276 14 2018-08-16 2020-12-15
114101 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 1723 1723 1723 14 2018-08-16 2020-12-15
114101 07-054 UROLOGÍA 811 811 811 14 2018-08-16 2020-12-15
114101 07-058 GINECOLOGÍA 1637 1637 1637 14 2018-08-16 2020-12-15
114101 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 905 905 905 14 2018-08-16 2020-12-15
114102 07-044 OFTALMOLOGÍA 97 97 97 14 2018-08-16 2020-12-15
114102 07-046 OTORRINOLARINGOLOGÍA 131 131 131 14 2018-08-16 2020-12-15
114103 07-003 CARDIOLOGÍA 2644 2644 2644 14 2018-08-16 2020-12-15
114103 07-004 CIRUGÍA GENERAL 2188 2188 2188 14 2018-08-16 2020-12-15
114103 07-012 DERMATOLOGÍA 1888 1888 1888 14 2018-08-16 2020-12-15
114103 07-014 ENDOCRINOLOGÍA ADULTO 994 994 994 14 2018-08-16 2020-12-15
114103 07-018 GASTROENTEROLOGÍA ADULTO 2640 2640 2640 14 2018-08-16 2020-12-15
114103 07-030 MEDICINA INTERNA 1594 1594 1594 14 2018-08-16 2020-12-15
114103 07-037 NEFROLOGÍA ADULTO 1171 1171 1171 14 2018-08-16 2020-12-15
114103 07-041 NEUROLOGÍA ADULTO 2050 2050 2050 14 2018-08-16 2020-12-15
114103 07-044 OFTALMOLOGÍA 3050 3050 3050 14 2018-08-16 2020-12-15
114103 07-046 OTORRINOLARINGOLOGÍA 2554 2554 2554 14 2018-08-16 2020-12-15
114103 07-048 PSIQUIATRÍA ADULTO 847 847 847 14 2018-08-16 2020-12-15
114103 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 631 631 631 14 2018-08-16 2020-12-15
114103 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 3934 3934 3934 14 2018-08-16 2020-12-15
114103 07-054 UROLOGÍA 1228 1228 1228 14 2018-08-16 2020-12-15
114103 07-058 GINECOLOGÍA 2082 2082 2082 14 2018-08-16 2020-12-15
114103 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 2251 2251 2251 14 2018-08-16 2020-12-15
114105 07-003 CARDIOLOGÍA 716 716 716 14 2018-08-16 2020-12-15
114105 07-004 CIRUGÍA GENERAL 734 734 734 14 2018-08-16 2020-12-15
114105 07-012 DERMATOLOGÍA 748 748 748 14 2018-08-16 2020-12-15
114105 07-014 ENDOCRINOLOGÍA ADULTO 687 687 687 14 2018-08-16 2020-12-15
114105 07-018 GASTROENTEROLOGÍA ADULTO 707 707 707 14 2018-08-16 2020-12-15
114105 07-030 MEDICINA INTERNA 567 567 567 14 2018-08-16 2020-12-15
114105 07-037 NEFROLOGÍA ADULTO 508 508 508 14 2018-08-16 2020-12-15
114105 07-041 NEUROLOGÍA ADULTO 762 762 762 14 2018-08-16 2020-12-15
114105 07-044 OFTALMOLOGÍA 734 734 734 14 2018-08-16 2020-12-15
114105 07-046 OTORRINOLARINGOLOGÍA 771 771 771 14 2018-08-16 2020-12-15
114105 07-048 PSIQUIATRÍA ADULTO 640 640 640 14 2018-08-16 2020-12-15
114105 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 486 486 486 14 2018-08-16 2020-12-15
114105 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 747 747 747 14 2018-08-16 2020-12-15
114105 07-054 UROLOGÍA 657 657 657 14 2018-08-16 2020-12-15
114105 07-058 GINECOLOGÍA 752 752 752 14 2018-08-16 2020-12-15
114105 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 539 539 539 14 2018-08-16 2020-12-15
114301 07-044 OFTALMOLOGÍA 715 715 715 14 2018-08-16 2020-12-15
114301 07-046 OTORRINOLARINGOLOGÍA 1002 1002 1002 14 2018-08-16 2020-12-15
114305 07-044 OFTALMOLOGÍA 17 17 17 6 2020-06-09 2020-12-15
114306 07-044 OFTALMOLOGÍA 170 170 170 14 2018-08-16 2020-12-15
114306 07-046 OTORRINOLARINGOLOGÍA 239 239 239 14 2018-08-16 2020-12-15
114307 07-046 OTORRINOLARINGOLOGÍA 586 586 586 14 2018-08-16 2020-12-15
114308 07-044 OFTALMOLOGÍA 885 885 885 14 2018-08-16 2020-12-15
114310 07-044 OFTALMOLOGÍA 176 176 176 14 2018-08-16 2020-12-15
114310 07-046 OTORRINOLARINGOLOGÍA 143 143 143 14 2018-08-16 2020-12-15
114315 07-044 OFTALMOLOGÍA 124 124 124 14 2018-08-16 2020-12-15
114315 07-046 OTORRINOLARINGOLOGÍA 182 182 182 14 2018-08-16 2020-12-15
114318 07-046 OTORRINOLARINGOLOGÍA 924 924 924 14 2018-08-16 2020-12-15
114323 07-044 OFTALMOLOGÍA 257 257 257 14 2018-08-16 2020-12-15
114323 07-046 OTORRINOLARINGOLOGÍA 256 256 256 14 2018-08-16 2020-12-15
114325 07-044 OFTALMOLOGÍA 175 175 175 14 2018-08-16 2020-12-15
114325 07-046 OTORRINOLARINGOLOGÍA 175 175 175 14 2018-08-16 2020-12-15
114327 07-048 PSIQUIATRÍA ADULTO 24 24 24 6 2019-01-08 2020-12-15
114331 07-044 OFTALMOLOGÍA 659 659 659 14 2018-08-16 2020-12-15
114331 07-046 OTORRINOLARINGOLOGÍA 1111 1111 1111 14 2018-08-16 2020-12-15
114407 07-044 OFTALMOLOGÍA 52 52 52 14 2018-08-16 2020-12-15
114608 07-044 OFTALMOLOGÍA 36 36 36 14 2018-08-16 2020-12-15
114608 07-046 OTORRINOLARINGOLOGÍA 36 36 36 14 2018-08-16 2020-12-15
114706 07-044 OFTALMOLOGÍA 41 41 41 14 2018-08-16 2020-12-15
114706 07-046 OTORRINOLARINGOLOGÍA 37 37 37 28 2018-08-16 2020-12-15
114714 07-044 OFTALMOLOGÍA 342 342 342 14 2018-08-16 2020-12-15
114796 07-044 OFTALMOLOGÍA 90 90 90 14 2018-08-16 2020-12-15
114796 07-046 OTORRINOLARINGOLOGÍA 80 80 80 14 2018-08-16 2020-12-15
114806 07-044 OFTALMOLOGÍA 36 36 36 14 2018-08-16 2020-12-15
200282 07-003 CARDIOLOGÍA 399 399 399 14 2018-08-16 2020-12-15
200282 07-004 CIRUGÍA GENERAL 481 481 481 14 2018-08-16 2020-12-15
200282 07-012 DERMATOLOGÍA 316 316 316 14 2018-08-16 2020-12-15
200282 07-014 ENDOCRINOLOGÍA ADULTO 241 241 241 14 2018-08-16 2020-12-15
200282 07-018 GASTROENTEROLOGÍA ADULTO 410 410 410 14 2018-08-16 2020-12-15
200282 07-030 MEDICINA INTERNA 484 484 484 14 2018-08-16 2020-12-15
200282 07-037 NEFROLOGÍA ADULTO 179 179 179 14 2018-08-16 2020-12-15
200282 07-041 NEUROLOGÍA ADULTO 435 435 435 14 2018-08-16 2020-12-15
200282 07-044 OFTALMOLOGÍA 531 531 531 14 2018-08-16 2020-12-15
200282 07-046 OTORRINOLARINGOLOGÍA 547 547 547 14 2018-08-16 2020-12-15
200282 07-048 PSIQUIATRÍA ADULTO 389 389 389 14 2018-08-16 2020-12-15
200282 07-049 PSIQUIATRÍA PEDIÁTRICA Y DE LA 230 230 230 14 2018-08-16 2020-12-15
200282 07-053 TRAUMATOLOGÍA Y ORTOPEDIA 511 511 511 14 2018-08-16 2020-12-15
200282 07-054 UROLOGÍA 408 408 408 14 2018-08-16 2020-12-15
200282 07-058 GINECOLOGÍA 417 417 417 14 2018-08-16 2020-12-15
200282 07-067 TRAUMATOLOGÍA Y ORTOPEDIA 181 181 181 14 2018-08-16 2020-12-15
Show code
#_#_#_#_#_#_#_#_LE
# 1 PUENTE ALTO      
# 2 SAN RAMON        
# 3 LA FLORIDA       
# 4 LA GRANJA        
# 5 LA PINTANA       
# 6 SAN JOSE DE MAIPO
# 7 PROVIDENCIA      
# 8 PIRQUE 
#_#_#_#_#_#_#_#_
brechas_gine_le_mod<-
janitor::clean_names(brechas_gine_le2)[,c("estab_orig_comuna","estab_dest", "presta_min", "corte_sigte", "n_registros")] %>% 
  dplyr::filter(presta_min %in% c("07-067","07-053", "07-046", "07-044", "07-004", "07-012", "07-058", "07-003", "07-041", "07-030", "07-054", "07-018", "07-014", "07-048", "07-037", "07-049")) %>%   
  dplyr::mutate(mes_14= month(corte_sigte), mes2=mes_14, ano_13=year(corte_sigte)) %>% 
  dplyr::arrange(estab_dest, presta_min, ano_13, mes_14) %>% 
  #seleccionamos la primera fila para cada uno
  dplyr::group_by(estab_dest, presta_min, ano_13, mes_14) %>% 
  dplyr::summarise(sum_le=sum(n_registros, na.rm=T), 
                   pa=sum(sum_le[estab_orig_comuna=="PUENTE ALTO"],na.rm=T)/sum_le, 
                   sr=sum(sum_le[estab_orig_comuna=="SAN RAMON"],na.rm=T)/sum_le, 
                   lf=sum(sum_le[estab_orig_comuna=="LA FLORIDA"],na.rm=T)/sum_le, 
                   lg=sum(sum_le[estab_orig_comuna=="LA GRANJA"],na.rm=T)/sum_le, 
                   lp=sum(sum_le[estab_orig_comuna=="LA PINTANA"],na.rm=T)/sum_le, 
                   sjm=sum(sum_le[estab_orig_comuna=="SAN JOSE DE MAIPO"],na.rm=T)/sum_le, 
                   prov=sum(sum_le[estab_orig_comuna=="PROVIDENCIA"],na.rm=T)/sum_le, 
                   pir= sum(sum_le[estab_orig_comuna=="PIRQUE"],na.rm=T)/sum_le) %>% 
  dplyr::ungroup() %>% 
  #para cada establecimiento, prestación y año, genero valores con los distintos meses del año si no están
  #dplyr::group_by(estab_dest, presta_min, ano_13) %>% 
  tidyr::complete(mes_14 = seq(1, 12)) %>% 
  #generamos una variable llamada ano-mes, para homologar nuestros datos a la base original
  dplyr::mutate(ano_mes=paste0(ano_13,"_",sprintf("%.2d", mes_14))) %>% 
  dplyr::ungroup() %>% 
  #filtro para que coincida con la base de datos de REM
  dplyr::filter(ano_mes %in% unlist(vector_ano_mes))


1.3. Combinación

Show code
#LEM= lista espera mensual
#LET = lista espera trimestral
#Hacer lo mismo con la LElas entradas por mes

#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_
#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_
# COMBINACION DE BASES
#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_

cons_brechas_gine_pre<-
janitor::clean_names(brechas_gine_REM2) %>% 
  dplyr::left_join(especialidades[,c(1,3)], by=c("cod_sigte"="Código SIGTE")) %>% 
  data.table::as.data.table() %>% 
  janitor::clean_names() %>% 
  dplyr::filter(cod_sigte %in% c("07-067","07-053", "07-046", "07-044", "07-004", "07-012", "07-058", "07-003", "07-041", "07-030", "07-054", "07-018", "07-014", "07-048", "07-037", "07-049")) %>% 
  dplyr::arrange(cod_sigte, ano, mes) %>% 
  dplyr::mutate(fecha=as.Date(paste0(ano,"_",mes,"_01"),"%Y_%m_%d")) %>% 
  #para cada establecimiento, prestación y año, genero valores con los distintos meses del año si no están
  dplyr::group_by(cod_sigte,especialidad_norma_820, ano) %>% 
  tidyr::complete(mes = seq(1, 12)) %>%
  dplyr::ungroup() %>% 
  dplyr::filter(ano>2017, ano<2021) %>% 
  janitor::clean_names() %>% 
  dplyr::select(cod_deis, ano, mes, cod_sigte, especialidad_norma_820, consultas, consultas_nueva, consultas_control, pertinentes, nsp, nsp_nueva, altas) %>% 
    dplyr::arrange(cod_deis, ano, mes, cod_sigte) %>%
  dplyr::left_join(brechas_gine_entradas_mod[,setdiff(names(brechas_gine_entradas_mod),"ano_mes")], by=c("cod_deis"="estab_dest", "cod_sigte"="presta_min", "ano"="ano", "mes"="mes"))%>%
  dplyr::left_join(brechas_gine_le_mod[,setdiff(names(brechas_gine_le_mod),"ano_mes")], by=c("cod_deis"="estab_dest", "cod_sigte"="presta_min", "ano"="ano_13", "mes"="mes_14")) %>% 
  dplyr::rename("entradas"="n_entradas_tot")%>% 
  dplyr::mutate(razon_do=consultas_nueva/entradas) %>% 
  #
  dplyr::mutate(fecha=as.Date(paste0(ano,"_",mes,"_01"),"%Y_%m_%d")) %>% 
  dplyr::mutate(trat_t=dplyr::case_when(ano==2020 & mes>= 4~1,T~ 0))


cons_brechas_gine<-
dplyr::mutate(cons_brechas_gine_pre,lev_ano_mes= as.numeric(factor(paste0(ano,"_",sprintf("%.2d", mes)),levels=vector_ano_mes$ano_mes))) %>% 
  dplyr::mutate(id=paste0(cod_deis,"_",cod_sigte))%>% 
   dplyr::mutate(trat_id=dplyr::case_when(cod_sigte=="07-058"~1,T~ 0))

Pendiente

A 200282 CRS PUENTE ALTO HOSPITAL PROVINCIA CORDILLERA no tenía ninguna información para mayo del 2020. La base de LE’s está bastante más incompleta en ese sentido. Además tiene meses 0 (ej., 2020- 0). Todavía no sé que es LEM. Aquellas columnas rem_ en algunos casos tienen valores 0, pero posiblemente son datos perdidos. Con todo, se consolidó una base de datos llamada cons_brechas_gine.

Show code
pv_data<-
panelView::panelview(entradas ~trat_t*trat_id, data=cons_brechas_gine, index = c("id","fecha"))
Show code
pv_data+
  sjPlot::theme_sjplot2()+
    theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5,angle = 60),
          legend.position="bottom",
          plot.caption=element_text(hjust=0))+
    #scale_y_continuous(breaks=seq(0,1000,50))+
  ggtitle("Vista de datos de panel")+
  ylab("Combinación (Hospital código DEIS, especialidad)")

Posteriormente, para reemplazar datos perdidos, se utilizó un modelo de imputación de series de tiempo por cada institución y código de prestación basado en suavizamiento (smoothing) Kalman correspondiente a modelos de series de tiempo estructurales. Se consolidaron los datos en una base de datos con nombre cons_brechas_gine_imp.


Show code
#https://choonghyunryu.github.io/dlookr/reference/get_transform.html
vec_columnas<-
c("consultas", "consultas_nueva", "consultas_control", "pertinentes", "nsp", "nsp_nueva", "altas", "entradas", "sum_le")


cons_brechas_gine%>%
ggplot() + #median
  facet_wrap(ano~cod_sigte) + 
  theme_bw() + 
  ylab("Especialidad/Año") + 
  xlab("Mes") + 
  theme(strip.text.x = element_text(size = 8, face = "bold"),
        legend.position = c(.95,0.02),
        plot.caption=element_text(hjust = 0),
        legend.key = element_rect(fill = NA))+
  stat_smooth(aes(y = consultas_control, x = mes, color = 'red'), fill = 'red', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
    stat_smooth(aes(y = consultas, x = mes, color = 'darkblue'), fill = 'darkblue', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = consultas_nueva, x = mes, color = 'cyan'), fill = 'darkblue', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = altas, x = mes, color = 'violet'), fill = 'violet', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = entradas, x = mes, color = 'brown'), fill = 'brown', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = nsp, x = mes, color = 'gray70'), fill = 'gray80', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = sum_le, x = mes, color = 'darkgreen'), fill = 'darkgreen', alpha = 0.2, fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = pertinentes, x = mes, color = 'yellow'), fill = 'yellow', alpha = 0.2, fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  scale_color_identity(name = "Medidas",
                          breaks = c("darkblue","red", "cyan", "violet","brown","gray70","darkgreen","yellow"),
                          labels = c("Control", "Consulta", "C_Nueva", "Altas","Entradas", "NSP","LE", "Pertinentes"), guide = "legend")+
    scale_x_continuous(
  breaks = seq(from = 1, to = 12, by =3))+
  guides(color=guide_legend(ncol=2,
  override.aes=list(fill=NA)))
Conjunto de Medidas por año y Código

Figure 1: Conjunto de Medidas por año y Código

Show code
#https://choonghyunryu.github.io/dlookr/reference/get_transform.html
vec_columnas<-
c("consultas", "consultas_nueva", "consultas_control", "pertinentes", "nsp", "nsp_nueva", "altas", "entradas", "sum_le")


cons_brechas_gine%>%
ggplot() + #median
  facet_wrap(ano~cod_deis) + 
  theme_bw() + 
  ylab("Hospital/Año") + 
  xlab("Mes") + 
  theme(strip.text.x = element_text(size = 8, face = "bold"),
        legend.position = c(.7,0.03),
        plot.caption=element_text(hjust = 0),
        legend.key = element_rect(fill = NA))+
  stat_smooth(aes(y = consultas_control, x = mes, color = 'red'), fill = 'red', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
    stat_smooth(aes(y = consultas, x = mes, color = 'darkblue'), fill = 'darkblue', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = consultas_nueva, x = mes, color = 'cyan'), fill = 'darkblue', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = altas, x = mes, color = 'violet'), fill = 'violet', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = entradas, x = mes, color = 'brown'), fill = 'brown', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = nsp, x = mes, color = 'gray70'), fill = 'gray80', alpha = 0.2,fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = sum_le, x = mes, color = 'darkgreen'), fill = 'darkgreen', alpha = 0.2, fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  stat_smooth(aes(y = pertinentes, x = mes, color = 'yellow'), fill = 'yellow', alpha = 0.2, fun.data = median_hilow, fun.args = list(conf.int = 0.5))+
  scale_color_identity(name = "Medidas",
                          breaks = c("darkblue","red", "cyan", "violet","brown","gray70","darkgreen","yellow"),
                          labels = c("Control", "Consulta", "C_Nueva", "Altas","Entradas", "NSP","LE", "Pertinentes"), guide = "legend")+
    scale_x_continuous(
  breaks = seq(from = 1, to = 12, by =3))+
  guides(color=guide_legend(ncol=4,
  override.aes=list(fill=NA)))
Conjunto de Medidas por año y Hospital

Figure 2: Conjunto de Medidas por año y Hospital


Session Info

Show code
Sys.getenv("R_LIBS_USER")
[1] "H:/.shortcut-targets-by-id/13vaH-zeqiYYS4Ss24jfuPKnDTAnAJSvM/Paper Brechas Gine/renv/library/R-4.1/x86_64-w64-mingw32;C:/Users/andre/AppData/Local/Temp/RtmpaisCpl/renv-system-library"
Show code
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Chile.1252  LC_CTYPE=Spanish_Chile.1252   
[3] LC_MONETARY=Spanish_Chile.1252 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Chile.1252    

attached base packages:
[1] parallel  stats     graphics  grDevices datasets  utils    
[7] methods   base     

other attached packages:
 [1] tabulizer_0.2.2     pglm_0.2-3          maxLik_1.5-2       
 [4] miscTools_0.6-26    missRanger_2.1.3    Amelia_1.8.0       
 [7] Rcpp_1.0.9          kableExtra_1.3.4    PanelMatch_2.0.1   
[10] doParallel_1.0.17   iterators_1.0.14    foreach_1.5.2      
[13] CausalMBSTS_0.1.1   KFAS_1.4.6          Synth_1.1-6        
[16] gsynth_1.2.1        plm_2.6-2           astsa_1.16         
[19] tsModel_0.6-1       ggforce_0.4.1       panelView_1.1.11   
[22] CausalImpact_1.2.7  bsts_0.9.8          xts_0.12.1         
[25] BoomSpikeSlab_1.2.5 Boom_0.9.10         MASS_7.3-58.1      
[28] data.table_1.14.2   gganimate_1.0.8     lubridate_1.8.0    
[31] forecast_8.18       compareGroups_4.5.1 zoo_1.8-11         
[34] sjPlot_2.8.11       imputeTS_3.3        janitor_2.1.0      
[37] forcats_0.5.2       stringr_1.4.1       dplyr_1.0.10       
[40] purrr_0.3.4         readr_2.1.3         tidyr_1.2.1        
[43] tibble_3.1.8        ggplot2_3.3.6       tidyverse_1.3.2    
[46] car_3.1-0           carData_3.0-5       devtools_2.4.4     
[49] usethis_2.1.6       pacman_0.5.1       

loaded via a namespace (and not attached):
  [1] estimability_1.4.1  downlit_0.4.2       bit64_4.0.5        
  [4] knitr_1.40          generics_0.1.3      callr_3.7.2        
  [7] mice_3.14.0         future_1.28.0       chron_2.3-58       
 [10] bit_4.0.4           tzdb_0.3.0          webshot_0.5.4      
 [13] xml2_1.3.3          httpuv_1.6.6        assertthat_0.2.1   
 [16] gargle_1.2.1        xfun_0.33           rJava_1.0-6        
 [19] hms_1.1.2           jquerylib_0.1.4     evaluate_0.17      
 [22] promises_1.2.0.1    fansi_1.0.3         progress_1.2.2     
 [25] dbplyr_2.2.1        readxl_1.4.1        DBI_1.1.3          
 [28] Rsolnp_1.16         quantmod_0.4.20     htmlwidgets_1.5.4  
 [31] googledrive_2.0.0   ellipsis_0.3.2      backports_1.4.1    
 [34] insight_0.18.4      vctrs_0.4.2         remotes_2.4.2      
 [37] TTR_0.24.3          sjlabelled_1.2.0    abind_1.4-5        
 [40] cachem_1.0.6        withr_2.5.0         MixMatrix_0.2.6    
 [43] collapse_1.8.8      HardyWeinberg_1.7.5 vroom_1.6.0        
 [46] bdsmatrix_1.3-6     emmeans_1.8.1-1     prettyunits_1.1.1  
 [49] svglite_2.1.0       urca_1.3-3          crayon_1.5.2       
 [52] labeling_0.4.2      glmnet_4.1-4        pkgconfig_2.0.3    
 [55] MatchIt_4.4.0       tweenr_2.0.2        nlme_3.1-159       
 [58] pkgload_1.3.0       nnet_7.3-18         rlang_1.0.6        
 [61] globals_0.16.1      lifecycle_1.0.3     miniUI_0.1.1.1     
 [64] stinepack_1.4       sandwich_3.0-2      modelr_0.1.9       
 [67] cellranger_1.1.0    polyclip_1.10-0     lmtest_0.9-40      
 [70] flextable_0.8.2     rngtools_1.5.2      datawizard_0.6.2   
 [73] Matrix_1.5-1        rgenoud_5.9-0.3     boot_1.3-28        
 [76] reprex_2.0.2        base64enc_0.1-3     processx_3.7.0     
 [79] googlesheets4_1.0.1 png_0.1-7           viridisLite_0.4.1  
 [82] parameters_0.19.0   shape_1.4.6         doRNG_1.8.2        
 [85] parallelly_1.32.1   ggeffects_1.1.3     scales_1.2.1       
 [88] memoise_2.0.1       magrittr_2.0.3      compiler_4.1.2     
 [91] lme4_1.1-30         tabulizerjars_1.0.1 snakecase_0.11.0   
 [94] cli_3.4.1           urlchecker_1.0.1    listenv_0.8.0      
 [97] ps_1.7.1            Formula_1.2-4       mgcv_1.8-40        
[100] tidyselect_1.1.2    stringi_1.7.6       highr_0.9          
[103] tseries_0.10-51     yaml_2.3.5          grid_4.1.2         
[106] lfe_2.8-8           sass_0.4.2          tools_4.1.2        
[109] rstudioapi_0.14     uuid_1.1-0          foreign_0.8-83     
[112] gridExtra_2.3       farver_2.1.1        digest_0.6.29      
[115] FNN_1.1.3.1         shiny_1.7.2         ggtext_0.1.2       
[118] quadprog_1.5-8      gridtext_0.1.5      broom_1.0.1        
[121] performance_0.10.0  later_1.3.0         writexl_1.4.0      
[124] optimx_2022-4.30    httr_1.4.4          gdtools_0.2.4      
[127] kernlab_0.9-31      effectsize_0.7.0.5  sjstats_0.18.1     
[130] Rdpack_2.4          colorspace_2.0-3    ranger_0.14.1      
[133] rvest_1.0.3         fs_1.5.2            truncnorm_1.0-8    
[136] splines_4.1.2       statmod_1.4.37      CBPS_0.23          
[139] CholWishart_1.1.2   renv_0.16.0         sessioninfo_1.2.2  
[142] systemfonts_1.0.4   xtable_1.8-4        jsonlite_1.8.2     
[145] nloptr_2.0.3        timeDate_4021.106   distill_1.5        
[148] LowRankQP_1.0.5     R6_2.5.1            profvis_0.3.7      
[151] pillar_1.8.1        htmltools_0.5.3     mime_0.12          
[154] glue_1.6.2          fastmap_1.1.0       minqa_1.2.4        
[157] codetools_0.2-18    pkgbuild_1.3.1      mvtnorm_1.1-3      
[160] utf8_1.2.2          lattice_0.20-45     bslib_0.4.0        
[163] numDeriv_2016.8-1.1 curl_4.3.2          officer_0.4.4      
[166] zip_2.2.1           survival_3.4-0      rmarkdown_2.17     
[169] munsell_0.5.0       sjmisc_2.8.9        haven_2.5.1        
[172] fracdiff_1.5-1      gtable_0.3.1        bayestestR_0.13.0  
[175] rbibutils_2.2.9    
Show code
warning(getwd())
save.image("__paso1.RData")
unlink("*_cache", recursive = T, force = T, expand = TRUE)
sesion_info <- devtools::session_info()
dplyr::select(
  tibble::as_tibble(sesion_info$packages),
  c(package, loadedversion, source)
) %>% 
  DT::datatable(filter = 'top', colnames = c('Row number' =1,'Variable' = 2, 'Percentage'= 3),
              caption = htmltools::tags$caption(
        style = 'caption-side: top; text-align: left;',
        '', htmltools::em('Packages')),
      options=list(
initComplete = htmlwidgets::JS(
        "function(settings, json) {",
        "$(this.api().tables().body()).css({
            'font-family': 'Helvetica Neue',
            'font-size': '50%', 
            'code-inline-font-size': '15%', 
            'white-space': 'nowrap',
            'line-height': '0.75em',
            'min-height': '0.5em'
            });",#;
        "}")))
Adams, Annette L. 2008. Encyclopedia of Epidemiology.” Thousand Oaks: SAGE Publications, Inc. https://doi.org/10.4135/9781412953948 NV - 2.
Aschwanden, Christie. 2015. Science Isnt Broken Its just a hell of a lot harder than we give it credit for.” FiveThirtyEight. https://fivethirtyeight.com/features/science-isnt-broken/#part1.
Bounthavong, Mark. 2018. Using inverse probability of treatment weights & Marginal structural models to handle time-varying covariates.” https://rpubs.com/mbounthavong/IPTW_MSM_Tutorial.
Cummiskey, Kevin, Bryan Adams, James Pleuss, Dusty Turner, Nicholas Clark, and Krista Watts. 2020. “Causal Inference in Introductory Statistics Courses.” Journal of Statistics Education 28 (1): 2–8. https://doi.org/10.1080/10691898.2020.1713936.
Gelman, Andrew, and Guido Imbens. 2013. “Why Ask Why? Forward Causal Inference and Reverse Causal Questions.” Working Paper 19614. Working Paper Series. National Bureau of Economic Research. https://doi.org/10.3386/w19614.
Hernán, Miguel A. 2001. “Conocimiento Experto, Confusión y Métodos Causales.” Gaceta Sanitaria 15: 44–48. https://doi.org/10.1007/BF02595718.
Hernán, Miguel A, Sonia Hernández-Díaz, and James M Robins. 2004. A structural approach to selection bias. Epidemiology (Cambridge, Mass.) 15 (5): 615–25. https://doi.org/10.1097/01.ede.0000135174.63482.43.
Hernán, Miguel Ángel, and James M Robins. 2020. Causal Inference: What If. Boca Raton: Chapman & Hall/CRC. https://cdn1.sph.harvard.edu/wp-content/uploads/sites/1268/2019/10/ci_hernanrobins_1oct19.pdf.
Hernán, Miguel A, and James M Robins. 2010. Causal inference.” CRC Boca Raton, FL.
Imbens, Guido W., and Donald B. Rubin. 2015. “Causality: The Basic Framework.” In Causal Inference for Statistics, Social, and Biomedical Sciences: An Introduction, 3–22. Cambridge University Press. https://doi.org/10.1017/CBO9781139025751.002.
Kaufman, Jay. 2020. Conceptos de Causalidad y Sesgos en Estudios Observacionales.” Evaluación de intervenciones: estudios cuasi-experimentales. Escuela de Salud Pública. Universidad de Chile. https://fivethirtyeight.com/features/science-isnt-broken/#part1.
Mansournia, Mohammad Ali, Mahyar Etminan, Goodarz Danaei, Jay S Kaufman, and Gary Collins. 2017. “Handling Time Varying Confounding in Observational Research.” BMJ 359. https://doi.org/10.1136/bmj.j4587.
Matthay, Ellicott C., Erin Hagan, Laura M. Gottlieb, May Lynn Tan, David Vlahov, Nancy E. Adler, and M. Maria Glymour. 2020. “Alternative Causal Inference Methods in Population Health Research: Evaluating Tradeoffs and Triangulating Evidence.” SSM - Population Health 10: 100526. https://doi.org/https://doi.org/10.1016/j.ssmph.2019.100526.
McGrath, Sean, Victoria Lin, Zilu Zhang, Lucia C Petito, Roger W Logan, Miguel A Hernán, and Jessica G Young. 2020. gfoRmula: An R Package for Estimating the Effects of Sustained Treatment Strategies via the Parametric g-formula. Patterns (New York, N.Y.) 1 (3). https://doi.org/10.1016/j.patter.2020.100008.
Muriel, Alfonso, Domingo Hernández, and Víctor Abraira. 2011. “Modelos Estructurales Marginales: Una Herramienta útil Que Proporciona Evidencia a Los Estudios Observacionales.” Nefrologia 2 (7): 7–13. https://doi.org/10.3265/NefrologiaSuplementoExtraordinario.pre2011.Dec.11267.
Naimi, Ashley I, Stephen R Cole, and Edward H Kennedy. 2016. An introduction to g methods.” International Journal of Epidemiology 46 (2): 756–62. https://doi.org/10.1093/ije/dyw323.
Pearl, Judea. 2003. “Statistics and Causal Inference: A Review.” TEST: An Official Journal of the Spanish Society of Statistics and Operations Research 12 (February): 281–345. https://doi.org/10.1007/BF02595718.
Platt, Robert W., Enrique F. Schisterman, and Stephen R. Cole. 2009. Time-modified Confounding.” American Journal of Epidemiology 170 (6): 687–94. https://doi.org/10.1093/aje/kwp175.
Robins, James. 1986. A new approach to causal inference in mortality studies with a sustained exposure period—application to control of the healthy worker survivor effect.” "Math. Modelling" 7: 1393–1512.
Robins, James M, Miguel Ángel Hernán, and Babette Brumback. 2000. Marginal Structural Models and Causal Inference in Epidemiology.” Epidemiology 11 (5). https://doi.org/10.1097/00001648-200009000-00011.
Rothman, A. n.d. Causal Inference in Data Science: Doubly Robust Estimation of G-Methods.” https://towardsdatascience.com/doubly-robust-estimators-for-causal-inference-in-statistical-estimation-3c00847e9db.
Rubin, Donald B. 1980. “Randomization Analysis of Experimental Data: The Fisher Randomization Test Comment.” Journal of the American Statistical Association 75 (371): 591–93.
Schisterman, Enrique F, Stephen R Cole, and Robert W Platt. 2009. Overadjustment bias and unnecessary adjustment in epidemiologic studies. Epidemiology (Cambridge, Mass.) 20 (4): 488–95. https://doi.org/10.1097/EDE.0b013e3181a819a1.
Tompsett, Daniel, Stijn Vansteelandt, Oliver Dukes, and Bianca De Stavola. 2022. “Gesttools: General Purpose G-Estimation in R.” Observational Studies 8 (1): 1–28. https://doi.org/10.1353/obs.2022.0003.
van der Wal, Willem M., and Ronald B. Geskus. 2011. ipw: An R Package for Inverse Probability Weighting.” Journal of Statistical Software 43 (13): 1–23. http://www.jstatsoft.org/v43/i13/.
Vansteelandt, Stijn, and Niels Keiding. 2011. “Invited Commentary: G-Computation–Lost in Translation?” Am J Epidemiol 173 (7): 739–42.

References